# --------------------------------------------------------------------------------------------------------------------
# Project:             Digital Payment System (DPS)
# Website:             http://code.google.com/p/dps-x509/
# Purpose of document: This class hold all of the attributes (we care about) for our csrs
# --------------------------------------------------------------------------------------------------------------------
import sys, string, logging

sys.path.append("..")
  
try:
  import keyczar.keys as keys
except ImportError:
  from keyczar import *
  

import dps.errors
import dps.utils
import dps.x509AttributeAndValue

# --------------------------------------------------------------------------------------------------------------------
class CsrParams:
  """ Class holds properties of a csr
      Not all properties are exposed only the ones of interest to us """ 

# --------------------------------------------------------------------------------------------------------------------
  def __init__(self):
    """ constructor """
    
    self.__subject_     = ""
    self.__publicKey_   = None
    
# --------------------------------------------------------------------------------------------------------------------
  def setPublicKey(self, publicKey):
    """ 
    setter
    @type publicKey: keyczar.keys.RsaPublicKey 
    """
    dps.utils.assertion(not publicKey or isinstance(publicKey, keys.RsaPublicKey), \
                        "CsrParams.setPubKey: pubkey type mismatch")
    self.__publicKey_ = publicKey

# --------------------------------------------------------------------------------------------------------------------
  def getPublicKey(self):
    """ 
    getter 
    @rtype: dps.x509AttribueAndValue.X509AttribueAndValueList
    """
    return self.__publicKey_

# --------------------------------------------------------------------------------------------------------------------
  def setSubject(self, subject):
    """ 
    setter
    @type subject: dps.x509AttribueAndValue.X509AttribueAndValueList
    """
    dps.utils.assertion(not subject or isinstance(subject, dps.x509AttributeAndValue.X509AttributeAndValueList), \
                        "CsrParams.setSubject: subject type mismatch")
    self.__subject_ = subject

# --------------------------------------------------------------------------------------------------------------------
  def getSubject(self):
    """ 
    getter 
    @rtype: dps.x509AttribueAndValue.X509AttribueAndValueList
    """
    return self.__subject_

# --------------------------------------------------------------------------------------------------------------------
  def __str__(self):
    """ str operator """
    val = "subject: "+str(self.__subject_)+" publicKey: "+dps.utils.stringify(self.__publicKey_)
    return val
